<template>
	<el-container>
		<el-header>
			<div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
				<el-button type="info" icon="el-icon-refresh" @click="refresh"></el-button> 
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.wx_name" placeholder="昵称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe>
                <el-table-column label="模板名称" prop="template_name"></el-table-column>
				<el-table-column label="可配送区域" prop="type" width="150"></el-table-column>
                <el-table-column label="首件(个)" prop="type" width="150"></el-table-column>
                <el-table-column label="运费(元)" prop="type" width="150"></el-table-column>
                <el-table-column label="续件(个)" prop="type" width="150"></el-table-column>
                <el-table-column label="续费(元)" prop="type" width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="260">
					<template #default="scope">
				 
                        <el-button-group>
                            <el-popconfirm title="确定删除吗？" @confirm="audit(scope.row, scope.$index,1)" v-if="scope.row.is_system == 0">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
						</el-button-group>

					</template>
				</el-table-column> 

			</scTable>
		</el-main>
	</el-container>

    <freightsave-dialog v-if="dialog.save" ref="freightsaveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></freightsave-dialog>
</template>

<script>
    import freightsaveDialog from './freight_tpl_save'
	export default {
		name: 'agreement',
        components: {
			freightsaveDialog
		},
		data() {
			return {
				dialog: {
					save: false
				},
				apiObj: this.$API.system.freight_teplate.list,
				selection: [],
				search: {
					keyword: null
				}
			}
		},
		methods: {
            //添加
			add(){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.freightsaveDialog.open()
				})
			},
			//编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.freightsaveDialog.open('edit').setData(row)
				})
			},
			async audit(row,dex,t=1){
				var reqData = {id: row.id,'status':t}
				var res = await this.$API.demo.withdraw_post.post(reqData);
				if(res.code == 200){
					this.$refs.table.refresh()
					this.$message.success("操作成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
			//批量删除
			async batch_del(){
				this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？如果删除项中含有子集将会被一并删除`, '提示', {
					type: 'warning'
				}).then(() => {
					var arr = this.selection
					var ob = []
					for(var i=0;i<arr.length;i++){
						  ob.push(arr[i].cid)
					}
					this.table_del({'cid':ob.join(",")})
				}).catch(() => {

				})
			},
			//表格选择后回调事件 
			selectionChange(selection){
				this.selection = selection;
			},
			//表格内开关
			async changeSwitch(val, row){
				var res = await this.$API.demo.permission.post({'id':row.id,'status':val})
				if(res.code == 200){
					this.visible = false;
					this.$message.success("操作成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
			//搜索
			upsearch(){
				this.$refs.table.upData(this.search)
			},
            refresh(){
                this.$refs.table.reload()
            },
			//本地更新数据
			handleSaveSuccess(data, mode){
				console.log(mode,"sssssssssssssss")
				if(mode=='add'){
					this.$refs.table.reload()
				}else if(mode=='edit'){
					this.$refs.table.reload()
				}
			}
		}
	}
</script>

<style>
.red{
    font-size: 15px;
    color:#ff3333
}
</style>

